package com.itheima.springbootsecurity.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.springbootsecurity.domain.Resource;
import com.itheima.springbootsecurity.mapper.ResourceMapper;
import com.itheima.springbootsecurity.service.ResourceService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 资源表 服务实现类
 * </p>
 *
 * @author faithwu
 * @since 2024-07-12
 */
@Service
public class ResourceServiceImpl extends ServiceImpl<ResourceMapper, Resource> implements ResourceService {

    @Autowired
    private ResourceMapper resourceMapper;

    @Override
    public List<String> getNoAuthResourcePathList() {
        LambdaQueryWrapper<Resource> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Resource::getAuth, 0);
        List<Resource> noAuthList = baseMapper.selectList(queryWrapper);
        List<String> pathList = noAuthList.stream().map(obj -> obj.getPath()).collect(Collectors.toList());
        return pathList;
    }

    @Override
    public List<String> getPathListByUserid(Integer userId) {
        return resourceMapper.getPathListByUserid(userId);
    }
}
